package tyk.Dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/***
 *@title BaseDao
 *@description <TODO description class purpose>
 *@author Tang'ya'kang
 *@VERSION 1.0.0
 *@CREATE 2023/5/4 22:25
 **/
public abstract class BaseDao {
    public static int executeUpdate(String sql, Object... params) throws SQLException {
        Connection connection= DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/javaweb","root","123456");
        PreparedStatement preparedStatement=connection.prepareStatement(sql);
        for(int i=1;i<=params.length;++i)
        {
            System.out.println(params[i-1]+"...");
            preparedStatement.setObject(i,params[i-1]);
        }
        int rows= 0;
        try {
            rows = preparedStatement.executeUpdate();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            return 0;
        }
        if(connection.getAutoCommit()) connection.close();
        return rows;
    }
}
